import struct
import base64
import math

def generate_flower_point_data(num_points, petals=5):

    points = []
    for i in range(num_points):
        angle = (i / num_points) * 2 * math.pi * petals
        radius = 0.5 + 0.5 * math.sin(petals * angle)
        x = radius * math.cos(angle)
        y = radius * math.sin(angle)
        z = i * 0.01  # Slightly spread out in Z to add depth
        intensity = i / num_points  # Gradually increase intensity
        ring = 1  # Constant ring value for simplicity
        time = i  # Use index as a placeholder for time
        # Ensure each point data is exactly 30 bytes long
        point_data = struct.pack('<ffffffi2x', x, y, z, intensity, intensity, time, ring)
        points.append(point_data)

    return b''.join(points)

def print_flower(encoded_data, width=120, height=60):

    point_data = base64.b64decode(encoded_data)
    num_points = len(point_data) // 30
    grid = [[' ' for _ in range(width)] for _ in range(height)]
    center_x, center_y = width // 2, height // 2

    for i in range(num_points):
        offset = i * 30
        extract = point_data[offset:offset+30]
        x, y, z, intensity, _, _, _ = struct.unpack('<ffffffi2x', extract)
        plot_x = int(center_x + x * 40)  # Adjust scale for better visibility
        plot_y = int(center_y - y * 40)
        if 0 <= plot_x < width and 0 <= plot_y < height:
            grid[plot_y][plot_x] = '*'

    for row in grid:
        print(''.join(row))

# Generate 500 points for the flower
num_points = 500
point_cloud_data = generate_flower_point_data(num_points)

# Encode the point cloud data into Base64
encoded_data = base64.b64encode(point_cloud_data).decode('utf-8')

# Print the flower shape on the console
print_flower(encoded_data, width=120, height=60)  # Adjust width and height if necessary

print(encoded_data)